﻿// -----------------------------------------------------------------------
// Copyright (c) David Kean. All rights reserved.
// -----------------------------------------------------------------------
extern alias pcl;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using pcl::System.Adaptation;
using pcl::System.Security.Cryptography;

namespace Portable.Security.Cryptography
{
    [TestClass]
    public class ProtectedDataTests
    {
        [TestMethod]
        public void Protected_CallsUnderlyingIProtectedDataProtect()
        {
            int callCount = 0;
            var protectedData = IProtectedDataMockFactory.OverrideProtect((userData, optionalEntropy) => { callCount++; return null; });
            var adapter = IProtectedDataFactoryFactory.Override(a => a.CreateProtectedData(), protectedData);
            var resolver = IAdapterResolverFactory.OverrideResolve(type => adapter);
            PlatformAdapter.SetResolver(resolver);

            ProtectedData.Protect(new byte[0], new byte[0]);

            Assert.AreEqual(1, callCount);
        }

        [TestMethod]
        public void Unprotected_CallsUnderlyingIProtectedDataUnprotect()
        {
            int callCount = 0;
            var protectedData = IProtectedDataMockFactory.OverrideUnprotect((userData, optionalEntropy) => { callCount++; return null; });
            var adapter = IProtectedDataFactoryFactory.Override(a => a.CreateProtectedData(), protectedData);
            var resolver = IAdapterResolverFactory.OverrideResolve(type => adapter);
            PlatformAdapter.SetResolver(resolver);

            ProtectedData.Unprotect(new byte[0], new byte[0]);

            Assert.AreEqual(1, callCount);
        }
    }
}
